<?php
/**
 * 后台登录控制
 * ============================================================================
 * * COPYRIGHT 2016-2019 xhadmin.com , and all rights reserved.
 * * WEBSITE: http://www.xhadmin.com;
 * ----------------------------------------------------------------------------
 * This is not a free software!You have not used for commercial purposes in the
 * premise of the program code to modify and use; and publication does not allow
 * any form of code for any purpose.
 * ============================================================================
 * Author: 寒塘冷月 QQ：274363574
 */
 
namespace app\api\controller;
use app\api\service\AuthService;

class Login extends Base
{
	
    public function index()
    {
        //exit('sa');
        if(!empty(session('admin'))){
            $this->returnMsg(401,'token过期，请重新登录');
        }        
		if (!$this->request->isPost()) {
            $this->returnMsg(400,'请求方法应该只支持post');//exit;
        } else {
            $username = $this->request->post('user_name', '', 'strip_tags,trim');
            $password = $this->request->post('pass_word', '', 'strip_tags,trim');
            // 用户信息验证
            try {
                $res = AuthService::checkLogin($username, $password);
                $this->returnMsg(200,'ok',$res);
            } catch (\Exception $e) {
                $this->returnMsg(500,$e->getMessage());
            }
        }
    }

	/*验证码*/
	public function Verify()
	{
	    return captcha();
	}

    /**
     * 退出登录
     */
    public function out()
    {
        session('admin', null);
        return redirect(url('admin/Login/index'));
        //$this->success('退出登录成功！', '@admin/login');
    }

	
}
